68a33e
@@ -620,8 +620,9 @@
public class XMLConfiguration extends AbstractHierarchicalFileConfiguration
             XMLBuilderVisitor builder = new XMLBuilderVisitor(document,
                     isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter());
             builder.processDocument(getRoot());
+            initRootElementText(document, getRootNode().getValue());
             return document;
-        } /* try */
+        }
         catch (DOMException domEx)
         {
             throw new ConfigurationException(domEx);
@@ -632,6 +633,34 @@
public class XMLConfiguration extends AbstractHierarchicalFileConfiguration
         }
     }
 
+    /**
+     * Sets the text of the root element of a newly created XML Document.
+     *
+     * @param doc the document
+     * @param value the new text to be set
+     */
+    private void initRootElementText(Document doc, Object value)
+    {
+        Element elem = doc.getDocumentElement();
+        NodeList children = elem.getChildNodes();
+
+        // Remove all existing text nodes
+        for (int i = 0; i < children.getLength(); i++)
+        {
+            org.w3c.dom.Node nd = children.item(i);
+            if (nd.getNodeType() == org.w3c.dom.Node.TEXT_NODE)
+            {
+                elem.removeChild(nd);
+            }
+        }
+
+        if (value != null)
+        {
+            // Add a new text node
+            elem.appendChild(doc.createTextNode(String.valueOf(value)));
+        }
+    }
+
     /**
      * Creates a new node object. This implementation returns an instance of the
      * <code>XMLNode</code> class.
